<template>
  <el-main>
    <h2>融资申请审核</h2>
    <el-form  :model="queryFrom" label-width="120px" inline>
      <el-form-item label="申请类型">
        <el-select v-model="queryFrom.jrProductType" placeholder="请选择">
          <el-option v-for="item in this.productTypes" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请状态">
        <el-select v-model="queryFrom.applyState" placeholder="请选择">
          <el-option v-for="item in this.applyStates" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item><br>
      <el-form-item label="查询日期">
        <div class="block">
          <el-date-picker
            v-model="queryFrom.startDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </div>
      </el-form-item>
      至
      <el-form-item>
        <div class="block">
          <el-date-picker
            v-model="queryFrom.endDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      :data="tableData"
      stripe
      style="width: 100%">
      <el-table-column
        prop="cfContractId"
        label="申请合同号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="loanMessage"
        label="贷款信息"
        width="180">
      </el-table-column>
      <el-table-column
        prop="jrProductType"
        label="申请类型">
        <template slot-scope="scope">
          <span v-for="item in productTypes" v-if="scope.row.jrProductType==item.id">
            {{item.name}}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="loanAmount"
        label="借款金额">
      </el-table-column>
      <el-table-column
        prop="monthLimit"
        label="借款期限">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="申请日期">
      </el-table-column>
      <el-table-column
        prop="companyName"
        label="资金方">
      </el-table-column>
      <el-table-column label="申请状态" width="120">
        <template slot-scope="scope">
          <div v-if="scope.row.applyState==1">
            申请中
          </div>
          <div v-else-if="scope.row.applyState==2">
            初审通过(待复审)
          </div>
          <div v-else-if="scope.row.applyState==3">
            初审不通过
          </div>
          <div v-else-if="scope.row.applyState==4">
            复审通过
          </div>
          <div v-else>
            复审不通过
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="300">
        <template slot-scope="scope">
          <div v-if="scope.row.applyState==1">
            <el-button @click="shenhe(scope.row)" type="text" size="small">审核</el-button>
          </div>
          <div v-else-if="scope.row.applyState==2">
            <el-button @click="shenhe(scope.row)" type="text" size="small">审核</el-button>
          </div>
          <div v-else-if="scope.row.applyState==3">
            <el-button @click="cha(scope.row)" type="text" size="small">查看</el-button>

          </div>
          <div v-else-if="scope.row.applyState==4">
            <el-button @click="cha(scope.row)" type="text" size="small">查看</el-button>
          </div>
          <div v-else-if="scope.row.applyState==5">

            <el-button @click="cha(scope.row)" type="text" size="small">查看</el-button>
          </div>
          <div v-else-if="scope.row.applyState==6">
            放款成功
          </div>
          <div v-else-if="scope.row.applyState==7">
            已成功
          </div>
          <div v-else-if="scope.row.applyState==8">
            已违约
          </div>
          <div v-else>
            审核中
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>10"
      :total="total"
      :page.sync="queryFrom.pageNum"
      :limit.sync="queryFrom.pageSize"
      @pagination="getList"
    />
    <!--    查看-->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible1"
      width="80%">
      <h1>|申请主题信息</h1><br>
      公寓名称：{{zf.premiseName}}<br><br>
      公司名称：{{zf.premiseName}}
      联系人：{{zf.premiseName}}<br><br>
      手机号：{{contas.signUserMobile}}
      申请时间：{{zf.createTime}}<br><br>
      法人姓名：{{contas.signUserName}}
      法人身份证：{{contas.signUserIdCard}}<br><br>
      公司地址：{{contas.cqAddress}}
      账户类型：<br><br>
      账户：
      开户行：<br>
      法人身份证：
      <h1>|贷款详细信息</h1><br>
      租客姓名：{{zf.tenantName}}
      租客身份证号：{{zf.tenantCardNo}}<br><br>
      租客手机号：{{zf.tenantPhone}}
      承租房间：{{zf.roomName}}<br><br>
      月租金：{{zf.monthRent}}元
      押金：{{zf.deposit}}元<br><br>
      租约起始日期：{{zf.startDate}}
      租约终止日期：{{zf.endDate}}<br><br>
      还款周期：1个月
      还款账期：月<br><br>
      服务费：
      利息：{{zhuti.monthLimit}}元<br><br>
      待收租金合计<br><br>
      租房合同<br><br>

      租客身份证：<br><br>
      <el-button v-if="sf==2" @click="tong">审核通过</el-button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <el-button v-if="sf==2" @click="bu">审核不通过</el-button>
      <span slot="footer" class="dialog-footer">
  </span>
    </el-dialog>
    <!--    收房贷-->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="80%">
      <h1>|申请主题信息</h1><br>
      公寓名称：{{contas.premiseName}}<br><br>
      公司名称：{{contas.premiseName}}
      联系人：{{contas.premiseName}}<br><br>
      手机号：{{contas.signUserMobile}}
      申请时间：{{contas.conSignTime}}<br><br>
      法人姓名：{{contas.signUserName}}
      法人身份证：{{contas.signUserIdCard}}<br><br>
      公司地址：{{contas.cqAddress}}
      账户类型：{{contas.accountType}}<br><br>
      账户：{{contas.bankCardNumber}}
      开户行：{{contas.bankOpen}}<br>
      法人身份证：
      <h1>|贷款详细信息</h1><br>
      业主姓名：{{contas.ownerName}}
      业主身份证号：{{contas.ownerIdCard}}<br><br>
      业主手机号：{{contas.ownerMobile}}
      业主银行卡号：{{contas.bankCard}}<br><br>
      业主开户行：{{contas.bankOpen}}<br><br>
      借款金额：{{zhuti.loanAmount}}元
      贷款利息：{{zhuti.reserve1}}元<br><br>
      一次性服务费：{{zhuti.reserve1}}元
      还款周期：1个月<br><br>
      租约起始日期：{{contas.leaseStartTime}}
      租约终止日期：{{contas.leaseEndTime}}<br><br>
      周期还款金额：{{zhuti.monthLimit}}元
      还款账期：{{zhuti.monthLimit}}月<br><br>
      房产证：<br><br>
      租房合同：<br><br>
      业主身份证：<br><br>
      业主银行卡：<br><br>
      维数公寓收取服务费:
      <el-input label="维数公寓收取服务费" style="width: 150px" v-if="sf==1"></el-input>
      <br><br>
      <el-button v-if="sf==2" @click="tong">审核通过</el-button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <el-button v-if="sf==2" @click="bu">审核不通过</el-button>
      <span slot="footer" class="dialog-footer">
  </span>
    </el-dialog>
  </el-main>
</template>

<script>

import { listInstallment,getObject,getContract,updateLoan} from "@/api/financial/installment";

export default {

  data(){
    return{
      productTypes:[
        {id:0,name:"请选择"},
        {id:1,name:"租房分期"},
        {id:2,name:"收房贷"},
        {id:3,name:"应收租约保理"}
        ],
      applyStates:[
        {id:0,name:"请选择"},
        {id:1,name:"申请中"},
        {id:2,name:"初审通过(待复审)"},
        {id:3,name:"初审不通过"},
        {id:4,name:"复审通过"},
        {id:5,name:"复审不通过"},
      ],
      total:null,
      tableData:[],
      queryFrom:{
        pageNum:1,
        pageSize:5,
      },
      //收房贷审核
      sf: 1,
      dialogVisible: false,
      dialogVisible1: false,
      contas: {},
      zhuti: {},
      zf: {},

    }
  },
  methods:{
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryFrom("queryFrom");
      this.handleQuery();
    },
    getList(){
      listInstallment(this.queryFrom).then(response => {
        this.tableData = response.data.list;
        this.total=response.data.total;
      });
    },
    cha(row) {
      this.dialogVisible = true;
      if (row.jrProductType == 2) {
        getObject(row).then(response => {
          console.log(row)
          this.zhuti = response.data;


        });
      } else if (row.jrProductType == 1) {
        getContract(row.cfContractId).then(response => {
          this.zf = response.data;
          this.dialogVisible1 = true;

        });
      }
    },
    //审核
    shenhe(row) {
      this.shenhes = row;
      this.cha(row);
      this.sf = 2;
      this.pd = row.jrProductType;

    },
    tong() {
      //.
       console.log(this.shenhes);
      //if(this.pd==2){
      this.shenhes.applyState = 2;
      updateLoan(this.shenhes).then(response => {
        console.log("审核：" + response)
        this.sf = 1
        this.dialogVisible = false;
        // alert(response.rows);
      })
      //}


    },
    bu() {
      //if(this.pd==2){
      this.shenhes.applyState = 3;
      updateLoan(this.shenhes).then(response => {
        console.log("审核：" + res)
        this.sf = 1
        this.dialogVisible = false;
        // alert(response.rows);
      })
    }
  },
  created() {
    this.getList();
  }
};
</script>
